(function () {
  let bTT = document.querySelector("#backToTop");
  let timer;
  bTT.onclick = function () {
    clearInterval(timer);
    timer = setInterval(() => {
      document.documentElement.scrollTop -= 50;
      if (document.documentElement.scrollTop <= 0) {
        clearInterval(timer);
      }
    }, 50);
  };

  //顶部小图标
  window.addEventListener(
    "scroll",
    function () {
      if (document.documentElement.scrollTop <= 0) {
        bTT.style.display = "none";
      } else {
        bTT.style.display = "block";
      }
    },
    true
  );
})();
